import logging, logging.handlers
import os

BaseDir = os.path.dirname(os.path.abspath(__file__))


def init_log():
    # 格式器
    fmt = '%(asctime)s %(levelname)s [%(name)s] [%(filename)s(%(funcName)s:%(lineno)d)] - %(message)s'
    formatt = logging.Formatter(fmt=fmt)
    # 处理器
    log_file = BaseDir + '/log/log.log'
    handler = logging.handlers.TimedRotatingFileHandler(log_file, when='midnight', interval=1, backupCount=7)
    handler.setLevel(logging.INFO)
    handler.setFormatter(formatt)
    # 日志器
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    logger.addHandler(handler)
